<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Product_Highlight_Model extends MY_Model{
	public function __construct(){
		parent::__construct();
	}

	public function getHighlightsProducts($addColumn=array(), $limit=PRODUCT_LIMIT) {
		$select = null;
		if(count($addColumn)>0){
			$select = implode(',', $addColumn);
		} else {
			$select = "a.id, a.title, a.slug, a.sale_flg, c.id as detail_id, c.code, c.image, c.price_new, f.image_folder AS shop_image_folder";
		}

		$this->db->select($select, true);
		$this->db->from($this->table_product_name . ' AS a');
		$this->db->join($this->table_product_details_name . ' c', 'a.id=c.product_id');
		$this->db->join($this->table_category_name . ' d', 'a.cate_id=d.id');
		$this->db->join($this->table_shop_name . ' e', 'a.shop_id=e.id');
		$this->db->join($this->table_user_name . ' f', 'e.user_id=f.id');
		$this->db->where('a.active_flg', 1);
		$this->db->where('a.deleted_at', null);
		$this->db->where('a.highlight_flg', 1);
		$this->db->where('c.is_avatar', 1);
		$this->db->where('c.deleted_at', null);
		$this->db->where('d.deleted_at', null);
		$this->db->where('e.deleted_at', null);
		$this->db->where('f.deleted_at', null);
		$this->db->order_by('a.created_at', 'DESC');
		$this->db->limit(PRODUCT_LIMIT);
		return $this->db->get()->result('Product_Entity');
	}
}